#ifndef __STDAFX_H__
#define __STDAFX_H__

/**	
	@file stdafx.h 
	Standard header file for GeorgeLib.
	Contains includes, type definitions, preprocessor defines and macros.
**/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <assert.h>
#include <windows.h>
#include "gl/glew.h"
#include "gl/freeglut.h"
#define _USE_MATH_DEFINES
#include <math.h>

#pragma comment(lib, "freeglut.lib")
#pragma comment(lib, "lua5.1.lib")
#pragma comment(lib, "glew32.lib")

// some maths
#define RADTODEG 180.0f/(float)M_PI
#define DEGTORAD (float)M_PI/180.0f
#define ZEROTOLERANCE 0.00001
#define ZEROTOLERANCEDIGITS 5

using namespace std;

#ifdef _USEDLL
	#define  __declspec()
#else
	#define DLLEXPORT
#endif

typedef unsigned __int8		uchar;		// unsigned char
typedef unsigned __int16	ushort;		// unsigned short
typedef unsigned __int32	uint;		// unsigned int
typedef unsigned __int64	ulonglong;	// unsigned long long

typedef const __int8		cchar;		// unsigned char
typedef const __int16		cshort;		// unsigned short
typedef const __int32		cint;		// unsigned int
typedef const __int64		clonglong;	// unsigned long long

typedef const unsigned __int8	cuchar;		// unsigned char
typedef const unsigned __int16	cushort;	// unsigned short
typedef const unsigned __int32	cuint;		// unsigned int
typedef const unsigned __int64	culonglong;	// unsigned long long

typedef const float			cfloat;
typedef	const double		cdouble;

#define DELETE_PTR(p) do { if(p) { delete (p); (p) = 0; } } while(0)
#define DELETE_ARR(p) do { if(p) { delete[] (p); (p) = 0; } } while(0)

#define ErrorMsg(cond,msg) { if(cond) { cout << msg << endl; return; } }
#define ErrorMsgReturn(cond,msg,r) { if(cond) { cout << msg << endl; return r; } }

/** PROPERTY_READONLY is used to declare a protected variable.
 We can use getter to read the variable.
 @param varType : the type of variable.
 @param varName : variable name.
 @param funName : "get + funName" is the name of the getter.
 @warning : The getter is a public virtual function, you should rewrite it first.
 The variables and methods declared after PROPERTY_READONLY are all public.
 If you need protected or private, please declare.
 */
#define PROPERTY_READONLY(varType, varName, funName)\
	protected: varType varName;\
	public: virtual varType get##funName(void);

#define PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\
	protected: varType varName;\
	public: virtual const varType& get##funName(void);

/** PROPERTY is used to declare a protected variable.
 We can use getter to read the variable, and use the setter to change the variable.
 @param varType : the type of variable.
 @param varName : variable name.
 @param funName : "get + funName" is the name of the getter.
 "set + funName" is the name of the setter.
 @warning : The getter and setter are public virtual functions, you should rewrite them first.
 The variables and methods declared after PROPERTY are all public.
 If you need protected or private, please declare.
 */
#define PROPERTY(varType, varName, funName)\
	protected: varType varName;\
	public: virtual varType get##funName(void);\
	public: virtual void set##funName(varType var);

#define PROPERTY_PASS_BY_REF(varType, varName, funName)\
	protected: varType varName;\
	public: virtual const varType& get##funName(void);\
	public: virtual void set##funName(const varType& var);

/** SYNTHESIZE_READONLY is used to declare a protected variable.
 We can use getter to read the variable.
 @param varType : the type of variable.
 @param varName : variable name.
 @param funName : "get + funName" is the name of the getter.
 @warning : The getter is a public inline function.
 The variables and methods declared after SYNTHESIZE_READONLY are all public.
 If you need protected or private, please declare.
 */
#define SYNTHESIZE_READONLY(varType, varName, funName)\
	protected: varType varName;\
	public: virtual varType get##funName(void) const { return varName; }

#define SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\
	protected: varType varName;\
	public: virtual const varType& get##funName(void) const { return varName; }

/** SYNTHESIZE is used to declare a protected variable.
 We can use getter to read the variable, and use the setter to change the variable.
 @param varType : the type of variable.
 @param varName : variable name.
 @param funName : "get + funName" is the name of the getter.
 "set + funName" is the name of the setter.
 @warning : The getter and setter are public  inline functions.
 The variables and methods declared after SYNTHESIZE are all public.
 If you need protected or private, please declare.
 */
#define SYNTHESIZE(varType, varName, funName)\
	protected: varType varName;\
	public: virtual varType get##funName(void) const { return varName; }\
	public: virtual void set##funName(varType var){ varName = var; }

#define SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\
	protected: varType varName;\
	public: virtual const varType& get##funName(void) const { return varName; }\
	public: virtual void set##funName(const varType& var){ varName = var; }

inline float detectzero(float num);
inline float detectzero(float num)
{
	// move the 5 decimal digits we want to before the decimal point
//	float temp = ( num * pow(10.0f, ZEROTOLERANCEDIGITS) );
	float temp = ( num * 100000 ); // because pow() is slow

	// make temp the numbers we don't want, then move them back to their original positions
//	temp = ( temp - (int) temp ) / pow(10.0f, ZEROTOLERANCEDIGITS);
	temp = ( temp - (int) temp ) / 0.00001f;

	// and then we remove those numbers from the original number(num)
	return num - temp;
}

#endif // __STDAFX_H__ //